package hn.sigit.interop.gmlproducers;

import hn.sigit.model.commons.IAdministrativeSource;

import java.util.ArrayList;
import java.util.List;

import org.deegree.commons.tom.primitive.PrimitiveType;
import org.deegree.feature.GenericFeature;
import org.deegree.feature.property.Property;
import org.deegree.feature.property.SimpleProperty;
import org.deegree.feature.types.GenericFeatureType;
import org.deegree.feature.types.property.PropertyType;
import org.deegree.feature.types.property.SimplePropertyType;
import org.deegree.gml.GMLVersion;

public class AdministrativeSourceGMLProducer extends GMLProducer<IAdministrativeSource> {
	private static final SimplePropertyType sidPropertyType = new SimplePropertyType(newQName("sID"), 1, 1, PrimitiveType.INTEGER, false, false, null);
	private static final SimplePropertyType acceptancePropertyType = new SimplePropertyType(newQName("acceptance"), 1, 1, PrimitiveType.DATE_TIME, false, false, null);
	private static final SimplePropertyType recordationPropertyType = new SimplePropertyType(newQName("recordation"), 1, 1, PrimitiveType.DATE_TIME, false, false, null);
	private static final SimplePropertyType submissionPropertyType = new SimplePropertyType(newQName("submission"), 1, 1, PrimitiveType.DATE_TIME, false, false, null);
	//private static final ArrayPropertyType archivePropertyType;
	
	private static GenericFeatureType administrativeSourceFeatureType;
	
	
	static {
		administrativeSourceFeatureType = buildFeatureType();
	}
	
	private static GenericFeatureType buildFeatureType() {
		List<PropertyType> propertyTypeList = new ArrayList<PropertyType>();
		propertyTypeList.add(sidPropertyType);
		propertyTypeList.add(acceptancePropertyType);
		propertyTypeList.add(recordationPropertyType);
		propertyTypeList.add(submissionPropertyType);
		
		return new GenericFeatureType(newQName("AdministrativeSource"), propertyTypeList, false);
	}
	
	public AdministrativeSourceGMLProducer(IAdministrativeSource administrativeSource) {
		super(administrativeSource);
	}

	@Override
	public GenericFeature buildFeature() {
		SimpleProperty sidProperty = new SimpleProperty(sidPropertyType, String.valueOf(getObjectFeature().getsID()), PrimitiveType.INTEGER);
		SimpleProperty acceptanceProperty = new SimpleProperty(acceptancePropertyType, getObjectFeature().getAcceptance().toString(), PrimitiveType.DATE_TIME);
		SimpleProperty recordationProperty = new SimpleProperty(recordationPropertyType, getObjectFeature().getRecordation().toString(), PrimitiveType.DATE_TIME);
		SimpleProperty submissionProperty = new SimpleProperty(submissionPropertyType, getObjectFeature().getSubmission().toString(), PrimitiveType.DATE_TIME);
		
		List<Property> propertyList = new ArrayList<Property>();
		propertyList.add(sidProperty);
		propertyList.add(acceptanceProperty);
		propertyList.add(recordationProperty);
		propertyList.add(submissionProperty);
		
		return new GenericFeature(administrativeSourceFeatureType, String.valueOf(getObjectFeature().getsID()), propertyList, GMLVersion.GML_31);
	}
}
